//----------------------------统一ajax全局配置------------------------------------
// console.log("ajaxSettings：", $.ajaxSettings);
//全局 的ajax事件
// $.ajaxComplete  无论请求是否成功 ,请求结束
// $.ajaxError  请求失败
// $.ajaxSend 请求数据已发送
// $.ajaxStart 开始发起请求
// $.ajaxStop  请求停止 (目前没有ajax正在进行的请求)
// $.success  请求成功
// 使用示例 :
// (function(window) {
var iframeNmae = (window.frameElement && window.frameElement.id) || "noIframe";
//定义一个获取数据的方法 = > 用于分页
$.ajaxSetup({
  timeout: 10000,
  start: function (info) {
    // console.log("ajax start", info);
  },
  beforeSend: function () {
    $("#loading").fadeIn();
    // console.log('开发请求之前....');
  },
  complete: function (xhr) {
    $("#loading").fadeOut();
    $(document).ajaxError(function (err) {
      console.log(err);
      // narn("error", err, "请求结果");
    });
    $(document).ajaxSuccess(function (res) {
      // console.log('ajaxSuccess', res);
    });
    $(document).ajaxStop(function (res) {
      // console.log('ajaxStop', res);
    });
  },
  // success: function(xhr) {
  // console.log('success', xhr);
  // },
  dataType: "json",
});

// 最终的接口: API
window.API = {};
var urls = {
  baseUrl: "/", //主路由
  data: [
    // "getLdData",
    "upProjecData",
    "getSid",
    "updateProjecData",
    "deleteProjectData",
    "login",
    "getLdData",
    "seach",
    "chcekone",
    "desiProjectApi",
  ],
};

urls.data.forEach(function (item) {
  window.API[item] = urls.baseUrl + item;
});

// //封装一个ajax的请求方法        ----------返回数据顺序：data数据,状态，错误信息
API.get = function (url, data, callback) {
  $.ajax({
    method: "get",
    url: API[url],
    data: data,
    dataType: "jsonp",
    success: callback,
    timeout: 10000,
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json",
    },
    error: function (err) {
      //请求失败后调用的函数
      console.log("ajax处理失败!", err);
      Toast(err, "error", 2000, 800);
      return err;
    },
    complete: function (xhr) {
      $("#loading").fadeOut();
    },
  });
};

API.post = function (url, data, callback) {
  // console.log('urls', API[url])
  // try {  //不能加，否则延迟好久
  $.ajax({
    method: "post",
    url: API[url],
    data: data,
    success: callback,
    traditional: true,
    timeout: 10000,
    // headers: {
    //   Accept: "application/json",
    //   "Content-Type": "application/json",
    // },
    error: function (err) {
      //请求失败后调用的函数
      console.log("ajax处理失败!", err);
      Toast(err, "error", 2000, 800);
      return err;
    },
    complete: function (xhr) {
      // if (count == 2) {
      //     $("#loading").fadeIn();
      //     console.log("多次请求", count)
      // } else {
      //     $("#loading").fadeOut();
      //     console.log("1次请求", count)
      // }
    },
    // } catch (error) {
    //     console.log(error)
    // }
  });
};

API.jsonp = function (url, data, callback) {
  //接口地址 、请求数据、回调函数
  $.ajax({
    method: "get",
    url: API[url],
    data: data,
    dataType: "jsonp",
    timeout: 10000,
    jsonpCallback: "myJsonp", //设定返回的回调函数
    success: callback,
    error: function (err) {
      //请求失败后调用的函数
      console.log("ajax处理失败!", err);
      Toast(err, "error", 2000, 800);
      return err;
    },
    complete: function (xhr) {
      $("#loading").fadeOut();
    },
  });
};

function setCookie(cname, cvalue, exdays) {
  var exp = new Date();
  exp.setTime(exp.getTime() + exdays * 24 * 60 * 60 * 1000); //6天过期
  document.cookie = cname + "=" + unescape(cvalue) + ";expires=" + exp.toGMTString();
  return true;
}

//读取cookie
function getCookie(name) {
  var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  // var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  if (arr) return unescape(arr[2]);
  return null;
}

function closeModie(node) {
  $("#close").click();
  $("#close").hide(1);
  // console.log(node)
}

//封装一个Toast 组件 (提供重复利用)--------------------------------
function Toast(msg, type, time1, time2, bottom) {
  var bottom = bottom || 40;
  //msg 提示的内容  ,type 类型风格
  // $(".toast").remove(); //先清掉
  var type = type || "success"; //warning error
  var htmlStr = '<div class="toast  ' + type + '" style=" bottom: ' + bottom + "px" + '">' + msg + "</div>";
  //插入body末尾处
  $(".toast").remove();
  $("body").append(htmlStr);
  setTimeout(function () {
    $(".toast").fadeOut(time2, function () {});
  }, time1);
}

// 退出登陆状态.glyphicon-log-out ,
$(".glyphicon-log-out").click(function (e) {
  setCookie("userName", "", -1);
  setCookie("cname", "", -1);
  setCookie("userType", "", -1);
  setCookie("sid", "", -1);
  window.location.href = "/login";
  // alert(e)
  // });
  //
  // // 退出登陆状态.glyphicon-log-out ,
  // $(".glyphicon-log-out").click(function (e) {
  //   setCookie("userName", "", -1);
  //   window.location.href = "/login";
  // alert(e)
});
// function setCookie(cname, cvalue, exdays) {
// var d = new Date();
// d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
// var expires = "expires=" + d.toUTCString();
// document.cookie = cname + "=" + cvalue + "; " + expires;
// }

//input失去焦点后 如果值发生改变后，触发补0
$("#addForm input[type='number']").blur(function (e) {
  var str = $(this).val();
  if (str == "" || isNaN(str) || str == null || str == undefined) {
    str = 0;
  }
  $(this).val(str);
});

$("#addForm").on("blur", "input[type='number']", function (e) {
  var str = $(this).val();
  if (str == "" || isNaN(str) || str == null || str == undefined) {
    str = 0;
  }
  $(this).val(str);
});

// 浮点数相加方法
// alert(FloatAdd("0", "4.4199"))
function FloatAdd(arg1, arg2) {
  var r1, r2, m;
  try {
    r1 = arg1.toString().split(".")[1].length;
  } catch (e) {
    r1 = 0;
  }
  try {
    r2 = arg2.toString().split(".")[1].length;
  } catch (e) {
    r2 = 0;
  }
  m = Math.pow(10, Math.max(r1, r2));
  var number_m = (arg1 * m + arg2 * m) / m;
  return parseFloat(number_m).toFixed(2);
  // return number_m;
}

// 浮点数相减方法
// alert(FloatSub("9999.22", "5555.11"))
function FloatSub(arg3, arg4) {
  var r11, r22, m2;
  try {
    r11 = arg3.toString().split(".")[1].length;
  } catch (e) {
    r11 = 0;
  }
  try {
    r22 = arg4.toString().split(".")[1].length;
  } catch (e) {
    r22 = 0;
  }
  m2 = Math.pow(10, Math.max(r11, r22));
  var number_m2 = (arg3 * m2 - arg4 * m2) / m2;
  return parseFloat(number_m2).toFixed(2);
  // return number_m;
}

// ----解决微信端字体巨大问题-----------------//
(function () {
  //   undefined;
  if (typeof WeixinJSBridge == "undefined") {
    // undefined;
    document.addEventListener("WeixinJSBridgeReady", function (e) {
      //   undefined;
      setTimeout(function () {
        // undefined;
        WeixinJSBridge.invoke(
          "setFontSizeCallback",
          {
            fontSize: 0,
          },
          function (res) {
            // undefined;
            // console.log(JSON.stringify(res));
          }
        );
      }, 0);
    });
  } else {
    // undefined;
    setTimeout(function () {
      //   undefined;
      WeixinJSBridge.invoke(
        "setFontSizeCallback",
        {
          fontSize: 0,
        },
        function (res) {
          //   undefined;
        //   console.log(JSON.stringify(res));
        }
      );
    }, 0);
  }
})();

//封装一个处理表单序列化数据格式
// function formatData(array) {
//     var data = {};
//     //处理需要提交的数据
//     $.each(array, function(index, item) {
//         data[item.name] = item.value;
//     });
//     return data;
// }

// })(window)

// 判断内容是否为空
function isStr(str) {
  if (str == "" || str == null || str == NaN || str == undefined || isNaN(str)) {
    return 0;
  } else {
    return str;
  }
}

// 空字符剔除方法
function remove_empty(obj) {
  obj.sid = window.API.sid;
  obj.status = window.API.status;
  obj.userType = window.API.userType;
  obj.engineer = window.API.engineer;
  obj.Server_rote = window.API.Server_rote || "2;";
  obj.rote = window.API.rote || "40";
  obj.customerType = window.API.customerType;
  obj.projectType = window.API.projectType;
  jsonLength2 = 0;
  jsonLength = 0;
  var obj2 = {}; //临时json容器 装全部字段
  for (let k in obj) {
    jsonLength2++; //总字段数
    v = obj[k];
    if (v === "" || v === null || v === "NaN" || v === undefined) {
      delete obj[k];
    } else {
      obj2[k] = v; //bij对象数据的键名在用变量代替时候需要用下标而不是点
      jsonLength++;
    }
  }
  //   console.log("总字段数", jsonLength);
  //   console.log("清理后字段数", jsonLength2);
  return obj;
}

//封装一个处理表单序列化数据格式
// function formatData(array) {
//   var data = {};
//   //处理需要提交的数据
//   $.each(array, function (index, item) {
//     data[item.name] = item.value;
//   });
//   return data;
// }

// -------------------封装原生httpREqust --------------------------
function ajax(options) {
  options = options || {}; //调用函数时如果options没有指定，就给它赋值{},一个空的Object
  options.type = (options.type || "GET").toUpperCase(); /// 请求格式GET、POST，默认为GET
  options.dataType = options.dataType || "json"; //响应数据格式，默认json

  var params = formatParams(options.data); //options.data请求的数据
  var xhr;

  //考虑兼容性
  if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
  } else if (window.ActiveObject) {
    //兼容IE6以下版本
    xhr = new ActiveXobject("Microsoft.XMLHTTP");
  }

  //启动并发送一个请求
  if (options.type == "GET") {
    xhr.open("GET", options.url + "?" + params, true);
    xhr.send(null);
  } else if (options.type == "POST") {
    xhr.open("post", options.url, true);

    //设置表单提交时的内容类型
    //Content-type数据请求的格式
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(params);
  }

  //    设置有效时间
  setTimeout(function () {
    if (xhr.readySate != 4) {
      xhr.abort();
    }
  }, options.timeout);

  //    接收
  //    options.success成功之后的回调函数  options.error失败后的回调函数
  //xhr.responseText,xhr.responseXML  获得字符串形式的响应数据或者XML形式的响应数据
  xhr.onreadystatechange = function () {
    if (xhr.readyState == 4) {
      var status = xhr.status;
      if ((status >= 200 && status < 300) || status == 304) {
        options.success && options.success(xhr.responseText, xhr.responseXML);
      } else {
        options.error && options.error(status);
      }
    }
  };
}

//格式化请求参数
function formatParams(data) {
  var arr = [];
  for (var name in data) {
    arr.push(encodeURIComponent(name) + "=" + encodeURIComponent(data[name]));
  }
  arr.push(("v=" + Math.random()).replace(".", ""));
  return arr.join("&");
}
// ----------------------封装原生ajax请求----------------------------------

//-----------------将输入后的文本填充到属性里面----------------//
$("#addForm").on("change", "input", function (e) {
  try {
    //-----------------将输入后的文本填充到属性里面----------------//
    var iframeNmae = (window.frameElement && window.frameElement.id) || "noIframe";
    if (iframeNmae != "iframe2") {
      //除修改项目之外
      //   $("#toviewTitel").remove();
      //   console.log(iframeNmae);
      //   } else if (iframeNmae == "noIframe") {
      //   console.log(iframeNmae);
      var allInputs = $("input");
      var varTitel = $(".titelToast");
      for (var k = 0; k < allInputs.length; k++) {
        var Value = $(allInputs[k]).val();
        if (Value == "" || Value == null) {
          Value = "未填写";
          // 空单元格不做属性填充
        } else if ($(allInputs[k]).hasClass("boxSN")) {
          var str2 = Value.replace(/[\u0391-\uFFE5]/gi, "");
          Value = str2;
          $(allInputs[k]).attr("value", Value); //去掉会导致定制项目没有value值保存爷们字符串后再打开修改时候没有数据
        } else if ($(allInputs[k]).hasClass("size")) {
          var str2 = Value.replace(/[\u0391-\uFFE5]/gi, "");
          Value = str2;
          $(allInputs[k]).attr("value", Value); //去掉会导致定制项目没有value值保存爷们字符串后再打开修改时候没有数据
        } else if ($(allInputs[k]).hasClass("boxJpgBuff")) {
          //保障图片input预先容器不被填充“未填写”  不做填充
        } else {
          if (iframeNmae == "iframe2") {
          } else {
            $(allInputs[k]).attr("value", Value); //去掉会导致定制项目没有value值保存爷们字符串后再打开修改时候没有数据
          }
        }

        $(allInputs[k]).attr("placeholder", Value);
        var className = $(allInputs[k]).attr("class") || "NOCLASS";
        // console.log(className);
        var inis = className.indexOf("titelToast");
        if (inis == "-1") {
          //   console.log(inis, className);
        } else {
          //   console.log(inis, className);
          var data = $(allInputs[k]).val() || "";
          //   console.log(data);
          $(allInputs[k]).attr("title", data);
        }
      }
    } else {
      //   console.log(iframeNmae);
    }
  } catch (error) {
    toast(error, "error", 2000);
  }
});
// ----------------------自动填充处理结束=----------

//文档禁止 touchmove事件--------------
document.ontouchmove = function (e) {
  e.preventDefault();
};

// 写出管理员类型--------------------------------------
var userType = "(" + getCookie("userType") + ")";
var username = getCookie("userName");
var cname = getCookie("cname");
$(".username").html(username);
var SuserType = getCookie("userType");
// console.log(userType)
if (userType == "(superAdmin)") {
  $(".userType").html("(" + cname + "-" + "超级管理员)");
} else if (userType == "(director)") {
  $(".userType").html("(" + cname + "-" + "总监)");
} else if (userType == "(manager)") {
  $(".userType").html("(" + cname + "-" + "经理)");
} else if (userType == "(admin)") {
  $(".userType").html("(" + cname + "-" + "管理员)");
} else if (userType == "(user)") {
  $(".userType").html("(" + cname + "-" + "普通用户)");
}

// 为空内容判断=========================

function isnUll(str) {
  if (str.length == 0 || str == null || isNaN(str) || typeof str == undefined) {
    return true;
  } else {
    return false;
  }
}

// ==================================输入内容规范处理开始============================//
// 获得焦点先清空
$("body").on("focus", "input", function (e) {
  //   console.log(e);
  $(this).val("");
});
// 处理非法输入 失去焦点时候
$("body").on("blur", "input[type='number']", function (e) {
  //离开刷新
  var str = $(this).val();
  var reg = /^(\.*)(\d+)(\.?)(\d{0,2}).*$/g;
  var str2 = str.replace(reg, "$2$3$4");
  $(this).val(str2);
  if (str == "" || isNaN(str) || str == null || str == undefined || isnUll(str)) {
    str = 0;
  } else {
    $(this).val(str);
    var number_thisVal = parseFloat($(this).val());
    if (number_thisVal < 0) {
      $(this).val(0);
    } else {
      $(this).val(number_thisVal);
    }
  }
});
// ==================================输入内容处理开始============================//

// 弹窗提示方法2
function showTip(tip, type) {
  var $tip = $("#tip");
  $tip
    .stop(true)
    .prop("class", "alert alert-" + type)
    .text(tip)
    .css("margin-left", -$tip.outerWidth() / 2)
    .fadeIn(500)
    .delay(2000)
    .fadeOut(500);
}

// bs4弹窗=============================
// function demo_dialog() {
//   let dia = bs4pop.dialog({
//     title: "对话框标题, 我还能拖拽呢",
//     content: "我是对话框内容",
//     closeBtn: true,
//     backdrop: "static",
//     btns: [
//       { label: "确定", className: "btn-primary", onClick(cb) {} },
//       { label: "取消", className: "btn-default", onClick(cb) {} },
//     ],
//     onShowStart: function () {
//       // console.log('onShowStart');
//     },
//     onShowEnd: function () {
//       // console.log('onShowEnd');
//     },
//     onHideStart: function () {
//       // console.log('onHideStart');
//     },
//     onHideEnd: function () {
//       // console.log('onHideEnd');
//     },
//     onDragStart: function () {
//       console.log("onDragStart");
//     },
//     onDragEnd: function () {
//       // console.log('onDragEnd');
//     },
//     onDrag: function () {
//       console.log("onDrag");
//     },
//   });
//
//   setTimeout(() => {
//     // dia.hide()
//   }, 2000);
// }

// function demo_alert() {}
// setTimeout(() => {
//   $("#alert").alert();
//   setTimeout(() => {
//     $("#alert").alert("close");
//   }, 2000);
// }, 2000);

//===========================================键盘监听事件======================================
$(document).keydown(function (event) {
  //   event.preventDefault();
  if (event.keyCode == 13) {
  } else if (event.keyCode == 27) {
    //ESC键盘
    $(".modal").hide(500);
    $(".modal-backdrop").hide(200);
    // $(".close").trigger("click");
    $("#loading").hide();
  }
});

// ===========================================表格导入事件=====================================
// ================表格导入方法 标准项目新建和修改统一用==================
var ExcelFlag;
$("#daoru").click(function (e) {
  //   $("#excel-file").trigger("click");

  layer.open({
    type: 1,
    title: "表格导入方法提示", //不显示标题栏 title : false/标题
    closeBtn: true,
    area: "300px;",
    shade: 0.7,
    id: "LAY_layuipro", //设定一个id，防止重复弹出
    resize: false,
    btn: ["直接导入", "下载模板"],
    btnAlign: "c",
    moveType: 1, //拖拽模式，0或者1,
    content: '<div style ="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;" ><strong> 导入表格只能是标准excel格式文件,如果导入失败可以下载标准模板，点击下方按钮下载或选择直接导入！</strong></div>',
    success: function (layero) {
      var btn = layero.find(".layui-layer-btn");
      btn.find(".layui-layer-btn1").attr({
        href: "http://zhilai-baojia.oss-cn-shenzhen.aliyuncs.com/file/20220717023644.xls",
        target: "_blank",
      });
    //   console.log(layero);
    },
    error: function (layer) {
    //   console.log(layer);
    },
    yes: function (layer) {
    //   console.log(layer);
      excelFileChange(e, "standard");
      $("#loading").fadeIn();
    },
    no: function (layer) {
    //   console.log(layer);
      $("#loading").fadeOut();
    },
    cancel: function (layer) {
    //   console.log(layer);
      $("#loading").fadeOut();
    },
  });
});
var excelDataJson = {};

function excelFileChange(e, type) {
  if (type == "standard") {
    ExcelFlag = type;
    // console.log(type);
  } else if (type == "designer") {
    ExcelFlag = type;
    // console.log(type);
  }
  $("#excel-file").trigger("click");
}
// function inputChange(e) {
$("#excel-file").change(function (e) {
  // console.log(e)
  //   layer.msg("223, 223");
  $(".layui-layer-close").trigger("click");
  var files = e.target.files;
  var file = files[0];
  const IMPORTFILE_MAXSIZE = 1 * 1024; //这里可以自定义控制导入文件大小
  if (file.size / 1024 > IMPORTFILE_MAXSIZE) {
    layer.msg("文件大小不能超过1MB");
    return;
  }
  var suffix = files[0].name.split(".")[1];
  if (suffix != "xls" && suffix != "xlsx") {
    layer.msg("只能导入excel!");
    return;
  }
  // console.log(files[0])
  // console.log(suffix)
  var fileReader = new FileReader();
  fileReader.onload = function (ev) {
    try {
      var data = ev.target.result;
      var workbook = XLSX.read(data, {
        type: "binary",
      }); // 以二进制流方式读取得到整份excel表格对象
      var a = workbook.SheetNames[0];
      var b = workbook.Sheets[a]; //内容为方式2
      var data2 = XLSX.utils.sheet_to_json(b); //内容为方式1
      // console.log(data2);//获取不全
      persons = [];
      // 表格的表格范围，可用于判断表头是否数量是否正确
      var fromTo = "";
      // 遍历每张表读取
      for (var sheet in workbook.Sheets) {
        if (workbook.Sheets.hasOwnProperty(sheet)) {
          fromTo = workbook.Sheets[sheet]["!ref"];
          if (!fromTo || fromTo == "") {
            layer.msg("文件内容为空, 导入失败，请检查表格格式是否正确！");
            return;
          }
          persons = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
          // break; // 如果只取第一张表，就取消注释这行
        }
      }
      // console.log(persons);
      return persons;
      //将persons赋值给要展示的表格数组里即可展示在界面
    } catch (e) {
      // alertMsg(2, '文件类型不正确, 请重新选择文件');
      layer.msg("文件类型不正确, 请重新选择文件");
      return;
    } finally {
      // console.log(persons);
      outFile(persons);
    }
  };
  // 以二进制方式打开文件
  if (files.length == 0) {
    layer.msg("文件内容长度为0, 导入失败，请检查表格格式是否正确！");
    return;
  }
  fileReader.readAsBinaryString(files[0]);
  e.target.value = "";
});

var json1;

function outFile(fileReader, type) {
  var sn = [],
    specifications = [],
    PackagingMaterials = [],
    electric = [],
    CircuitBard = [],
    powder = [],
    steel = [],
    other = [],
    lock = [],
    hardware = [],
    wire = [];
  //   console.log(fileReader);
  excelDataJson = fileReader;
  for (var key in excelDataJson) {
    // console.log(key);
    // console.log(excelDataJson[key]);
    var json2 = excelDataJson[key];
    json1 = json2;
    for (var key2 in json2) {
      //   console.log(key2);
      //   console.log(json2[key2]);
      var str = json2[key2];
      var x;
      if (key2 != "项目") {
        sn.push(key2);
      }
      switch (str) {
        case "项目":
          x = "品号";
          //   for (var key2 in json2) {
          //     sn.push(key2);
          //   }
          break;
        case "规格":
          x = "规格";
          for (var key2 in json2) {
            specifications.push(json2[key2]);
          }
          break;
        case "包材":
          x = "包材";
          for (var key2 in json2) {
            PackagingMaterials.push(parseFloat(json2[key2]).toFixed(2));
          }

          break;
        case "电控件":
          x = "电控件";
          for (var key2 in json2) {
            electric.push(parseFloat(json2[key2]).toFixed(2));
          }

          break;
        case "电路板":
          x = "电路板";
          for (var key2 in json2) {
            CircuitBard.push(parseFloat(json2[key2]).toFixed(2));
          }

          break;
        case "粉末":
          x = "粉末";
          for (var key2 in json2) {
            powder.push(parseFloat(json2[key2]).toFixed(2));
          }

          break;
        case "钢材":
          x = "钢材";
          for (var key2 in json2) {
            steel.push(parseFloat(json2[key2]).toFixed(2));
          }

          break;
        case "其他":
          x = "其他";
          for (var key2 in json2) {
            other.push(parseFloat(json2[key2]).toFixed(2));
          }
          break;
        case "锁":
          x = "锁";
          for (var key2 in json2) {
            lock.push(parseFloat(json2[key2]).toFixed(2));
          }
          //   console.log(lock);
          break;
        case "五金":
          x = "五金";
          for (var key2 in json2) {
            hardware.push(parseFloat(json2[key2]).toFixed(2));
          }

          break;
        case "线材":
          x = "线材";
          for (var key2 in json2) {
            wire.push(parseFloat(json2[key2]).toFixed(2));
          }
          break;
        default:
          x = "表格处理完";
      }
    }
  }

  console.log(sn, specifications, PackagingMaterials, electric, CircuitBard, powder, steel, other, lock, hardware, wire);
  if (ExcelFlag == "standard") {
    // console.log(ExcelFlag);
    var boxSNs = $(".sn");
    var boxTypes = $(".boxType");
    var PackMates = $(".PackMates");
    var devices = $(".devices");
    var Pcb = $(".Pcb");
    var fenmo = $(".fenmo");
    var metals = $(".metals");
    var others = $(".others");
    var locks = $(".lock");
    var wujins = $(".wujin");
    var cables = $(".cable");
    // console.log(boxTypes);
    for (var i = 1; i < PackagingMaterials.length; i++) {
      //SN数量不能用来循环用
      $(boxSNs[i - 1]).val(sn[i]);
      $(boxSNs[i - 1]).html(sn[i]);
    }
    for (var i = 1; i < specifications.length; i++) {
      $(boxTypes[i - 1]).val(specifications[i]);
      $(boxTypes[i - 1]).html(specifications[i]);
    }
    for (var i = 1; i < PackagingMaterials.length; i++) {
      $(PackMates[i - 1]).val(PackagingMaterials[i]);
      $(PackMates[i - 1]).html(PackagingMaterials[i]);
    }
    for (var i = 1; i < electric.length; i++) {
      $(devices[i - 1]).val(electric[i]);
      $(devices[i - 1]).html(electric[i]);
    }
    for (var i = 1; i < CircuitBard.length; i++) {
      $(Pcb[i - 1]).val(CircuitBard[i]);
      $(Pcb[i - 1]).html(CircuitBard[i]);
    }
    for (var i = 1; i < powder.length; i++) {
      $(fenmo[i - 1]).val(powder[i]);
      $(fenmo[i - 1]).html(powder[i]);
    }
    for (var i = 1; i < steel.length; i++) {
      $(metals[i - 1]).val(steel[i]);
      $(metals[i - 1]).html(steel[i]);
    }
    for (var i = 1; i < other.length; i++) {
      $(others[i - 1]).val(other[i]);
      $(others[i - 1]).html(other[i]);
    }
    for (var i = 1; i < lock.length; i++) {
      $(locks[i - 1]).val(lock[i]);
      $(locks[i - 1]).html(lock[i]);
    }
    for (var i = 1; i < hardware.length; i++) {
      $(wujins[i - 1]).val(hardware[i]);
      $(wujins[i - 1]).html(hardware[i]);
    }
    for (var i = 1; i < wire.length; i++) {
      //   console.log(wire);
      $(cables[i - 1]).val(wire[i]);
      $(cables[i - 1]).html(wire[i]);
    }
    $("#loading").fadeOut();
    layer.msg(x);
    setTimeout(() => {
      $("#reset").trigger("click");
    }, 2000);
  } else if (ExcelFlag == "designer") {
    // console.log(ExcelFlag);
  }
}
// =============================表格导入方法结束============================================
